<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var arr = [
        {
          name: "张三1",
          age: 19,
          gender: "男",
        },
        {
          name: "张三2",
          age: 20,
          gender: "男",
        },
        {
          name: "张三3",
          age: 24,
          gender: "男",
        },
        {
          name: "张三4",
          age: 22,
          gender: "男",
        },
        {
          name: "张三5",
          age: 25,
          gender: "女",
        },
        {
          name: "张三6",
          age: 26,
          gender: "男",
        },
      ];
      //筛选出所有的男性  再筛选出年龄大于20的所有用户
      //   var arr2 = [];
      //   arr.forEach((item) => {
      //     // console.log(item);
      //     if (item.gender === "男") arr2.push(item);
      //   });
      //   //   console.log(arr2);
      //   var arr3 = [];
      //   arr2.forEach((item) => {
      //     if (item.age > 20) arr3.push(item);
      //   });
      //   console.log(arr3);

      //
      //
      //
      //filter方法

      var arr3 = arr
        .filter((item) => item.gender === "男")
        .filter((item) => item.age > 20);
      console.log(arr3);
    </script>
  </body>
</html>
